<!DOCTYPE HTML>
<html lang="zh-CN">

<head>
    <!--Setting-->
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="IE=Edge,chrome=1">
    <meta http-equiv="Cache-Control" content="no-siteapp">
    <meta http-equiv="Cache-Control" content="no-transform">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">
    <meta name="apple-mobile-web-app-capable" content="涛哥的博客">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no,email=no,adress=no">
    <meta name="browsermode" content="application">
    <meta name="screen-orientation" content="portrait">
    <meta name="theme-version" content="1.2.3">
    <meta name="root" content="/">
    <link rel="dns-prefetch" href="https://jaredtao.github.io">
    <!--SEO-->

<meta name="keywords" content="Qt,持续集成(CI)" />


<meta name="description" content="
简介
Qt项目的编译流程
Qt项目的发布流程
查找依赖
制作包
上传


定制发布流程
发布时机
打包步骤
多平台发布
最终配置
windows版的最终配置
MacOS最终配置


结果和代码..." />


<meta name="robots" content="all" />
<meta name="google" content="all" />
<meta name="googlebot" content="all" />
<meta name="verify" content="all" />
    <!--Title-->

<title>
    
    玩转Qt(11)-github-Actions自动化发行 |
    
    涛哥的博客
</title>

<link rel="alternate" href="/atom.xml" title="涛哥的博客" type="application/atom+xml">


<link rel="icon" href="/favicon.ico">

    


<link rel="stylesheet" href="/css/bootstrap.min.css?rev=3.3.7.css">
<link rel="stylesheet" href="/css/font-awesome.min.css?rev=4.7.0.css">
<link rel="stylesheet" href="/css/style.css?rev=@@hash.css">

    
<div class="hide">
    <script type="text/javascript">
    var cnzz_protocol = (("https:" == document.location.protocol) ? " https://" : " http://");
    document.write(unescape("%3Cspan class='cnzz_stat_icon_1263868967 hide' %3E%3Cscript%20src%3D%22https%3A%2F%2Fs95.cnzz.com%2Fz_stat.php%3Fweb_id%3D1272564536%22%3E%3C%2Fscript%3E%3C/span%3E%3Cscript src='" + cnzz_protocol + "s19.cnzz.com/z_stat.php%3Fid%3D1263868967%26show%3Dpic1' type='text/javascript'%3E%3C/script%3E"));
    </script>
</div>




    

<script>
(function() {
    var bp = document.createElement('script');
    var curProtocol = window.location.protocol.split(':')[0];
    if (curProtocol === 'https') {
        bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
    } else {
        bp.src = 'http://push.zhanzhang.baidu.com/push.js';
    }
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(bp, s);
})();
</script>

<meta name="generator" content="Hexo 4.2.1"></head>
<!--[if lte IE 8]>
<style>
    html{ font-size: 1em }
</style>
<![endif]-->
<!--[if lte IE 9]>
<div style="ie">你使用的浏览器版本过低，为了你更好的阅读体验，请更新浏览器的版本或者使用其他现代浏览器，比如Chrome、Firefox、Safari等。</div>
<![endif]-->
<body>
    <header class="main-header"  style="background-image:url(
    http://snippet.shenliyang.com/img/banner.jpg)"
     >
    <div class="main-header-box">
        <a class="header-avatar" href="/" title='JaredTao'>
            <img src="/img/avatar.jpg" alt="logo头像" class="img-responsive center-block">
        </a>
        <div class="branding">
            <!--<h2 class="text-hide">Snippet主题,从未如此简单有趣</h2>-->
            
            <h2>
                单枪匹马亦对饮，历经磨难记初心
            </h2>
            
        </div>
    </div>
</header>
    <nav class="main-navigation">
    <div class="container">
        <div class="row">
            <div class="col-sm-12">
                <div class="navbar-header"><span class="nav-toggle-button collapsed pull-right" data-toggle="collapse" data-target="#main-menu" id="mnav">
                        <span class="sr-only"></span>
                        <i class="fa fa-bars"></i>
                    </span>
                    <a class="navbar-brand" href="https://jaredtao.github.io">
                        涛哥的博客</a>
                </div>
                <div class="collapse navbar-collapse" id="main-menu">
                    <ul class="menu">
                        
                        <li role="presentation" class="text-center">
                            <a href="/"><i class="fa "></i>
                                首页</a>
                        </li>
                        
                        <li role="presentation" class="text-center">
                            <a href="/categories/玩转Qt/"><i class="fa "></i>
                                玩转Qt</a>
                        </li>
                        
                        <li role="presentation" class="text-center">
                            <a href="/categories/玩转Qml/"><i class="fa "></i>
                                玩转Qml</a>
                        </li>
                        
                        <li role="presentation" class="text-center">
                            <a href="/categories/玩转QtQuick/"><i class="fa "></i>
                                玩转QtQuick</a>
                        </li>
                        
                        <li role="presentation" class="text-center">
                            <a href="/categories/涛哥的博客/"><i class="fa "></i>
                                涛哥的博客</a>
                        </li>
                        
                        <li role="presentation" class="text-center">
                            <a href="/archives/"><i class="fa "></i>
                                时间轴</a>
                        </li>
                        
                    </ul>
                </div>
            </div>
        </div>
    </div>
</nav>
    <section class="content-wrap">
        <div class="container">
            <div class="row">
                <main class="col-md-8 main-content m-post">
                    <p id="process"></p>
<article class="post">
    <div class="post-head">
        <h1 id="玩转Qt(11)-github-Actions自动化发行">
            
            玩转Qt(11)-github-Actions自动化发行
            
        </h1>
        <div class="post-meta">
    
    <span class="categories-meta fa-wrap">
        <i class="fa fa-folder-open-o"></i>
        <a class="category-link" href="/categories/%E7%8E%A9%E8%BD%ACQt/">玩转Qt</a>
    </span>
    
    
    <span class="fa-wrap">
        <i class="fa fa-tags"></i>
        <span class="tags-meta">
            
            <a class="tag-link" href="/tags/Qt/" rel="tag">Qt</a> <a class="tag-link" href="/tags/%E6%8C%81%E7%BB%AD%E9%9B%86%E6%88%90-CI/" rel="tag">持续集成(CI)</a>
            
        </span>
    </span>
    
    
    
    <span class="fa-wrap">
        <i class="fa fa-clock-o"></i>
        <span class="date-meta">
            2019/12/03</span>
    </span>
    
    <span class="fa-wrap">
        <i class="fa fa-eye"></i>
        <span id="busuanzi_value_page_pv"></span>
    </span>
    
    
</div>
        
        
    </div>
    
<div id="post-gallery">
    
    <img src="/images/QtActions2/2.png" alt="gallery-img" class="gallery">
    
</div>

    <div class="post-body post-content">
        <ul>
<li><a href="#%e7%ae%80%e4%bb%8b">简介</a></li>
<li><a href="#qt%e9%a1%b9%e7%9b%ae%e7%9a%84%e7%bc%96%e8%af%91%e6%b5%81%e7%a8%8b">Qt项目的编译流程</a></li>
<li><a href="#qt%e9%a1%b9%e7%9b%ae%e7%9a%84%e5%8f%91%e5%b8%83%e6%b5%81%e7%a8%8b">Qt项目的发布流程</a><ul>
<li><a href="#%e6%9f%a5%e6%89%be%e4%be%9d%e8%b5%96">查找依赖</a></li>
<li><a href="#%e5%88%b6%e4%bd%9c%e5%8c%85">制作包</a></li>
<li><a href="#%e4%b8%8a%e4%bc%a0">上传</a></li>
</ul>
</li>
<li><a href="#%e5%ae%9a%e5%88%b6%e5%8f%91%e5%b8%83%e6%b5%81%e7%a8%8b">定制发布流程</a><ul>
<li><a href="#%e5%8f%91%e5%b8%83%e6%97%b6%e6%9c%ba">发布时机</a></li>
<li><a href="#%e6%89%93%e5%8c%85%e6%ad%a5%e9%aa%a4">打包步骤</a></li>
<li><a href="#%e5%a4%9a%e5%b9%b3%e5%8f%b0%e5%8f%91%e5%b8%83">多平台发布</a></li>
<li><a href="#%e6%9c%80%e7%bb%88%e9%85%8d%e7%bd%ae">最终配置</a><ul>
<li><a href="#windows%e7%89%88%e7%9a%84%e6%9c%80%e7%bb%88%e9%85%8d%e7%bd%ae">windows版的最终配置</a></li>
<li><a href="#macos%e6%9c%80%e7%bb%88%e9%85%8d%e7%bd%ae">MacOS最终配置</a></li>
</ul>
</li>
<li><a href="#%e7%bb%93%e6%9e%9c%e5%92%8c%e4%bb%a3%e7%a0%81">结果和代码</a></li>
</ul>
</li>
</ul>
<h2 id="简介"><a href="#简介" class="headerlink" title="简介"></a>简介</h2><p>在上一篇文章《github-Actions自动化编译》中，介绍了github-Actions的基本用法，</p>
<p>本文来介绍github-Actions的自动化发布。</p>
<h2 id="Qt项目的编译流程"><a href="#Qt项目的编译流程" class="headerlink" title="Qt项目的编译流程"></a>Qt项目的编译流程</h2><p>先来回顾一下,上一篇文章中的Qt项目的编译流程</p>
<ol>
<li><p>安装Qt环境</p>
<p>这一步用第三方Action模板：<a href="https://github.com/jurplel/install-qt-action" target="_blank" rel="noopener">install-qt-action</a></p>
</li>
<li><p>获取项目代码</p>
<p>这一步用Actions官方核心模板：<a href="https://github.com/actions/checkout" target="_blank" rel="noopener">actions/checkout</a></p>
</li>
<li><p>执行qmake、make</p>
<p> 这一步用自定义脚本，也可以换成cmake、qbs、gn、ninja等构建工具</p>
</li>
<li><p>执行test</p>
<p> 这一步可以引入单元测试、自动化UI测试等。暂无完善的方案，以后再说。</p>
</li>
<li><p>发布</p>
<p> 见下文。</p>
</li>
</ol>
<h2 id="Qt项目的发布流程"><a href="#Qt项目的发布流程" class="headerlink" title="Qt项目的发布流程"></a>Qt项目的发布流程</h2><p>Qt程序在编译完成后，发布的大致流程是：</p>
<p>1、 查找依赖库</p>
<p>2、制作压缩包或者安装包</p>
<p>3、上传压缩包或者安装包到网站、网盘。</p>
<h3 id="查找依赖"><a href="#查找依赖" class="headerlink" title="查找依赖"></a>查找依赖</h3><p>Qt官方提供的查找依赖库的命令行工具，包括：Windows平台的Windeployqt、MacOS平台的Macosdeployqt。</p>
<p>在这两个平台，只使用Qt库的情况下，这两个工具足够了。</p>
<h3 id="制作包"><a href="#制作包" class="headerlink" title="制作包"></a>制作包</h3><p>做压缩包比较简单。(我们常说的‘绿色软件’，就是一个压缩包)</p>
<p>一般安装7z、rar之类的压缩工具，用一条命令行就行了。</p>
<p>涛哥这里再说一下，github-Actions给所有平台都提供了PowerShell，而PowerShell内置了压缩命令Compress-Archive。</p>
<p>使用也很简单，只要路径和名字，例如：</p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">Compress-Archive</span> -Path .\MyFolder <span class="string">'MyRelease.zip'</span></span><br></pre></td></tr></table></figure>

<p>做安装包，Qt官方有功能很全面的安装包制作工具：QtInstallFrameWork, 稍微翻看一下文档或者例子即可。本文先不展开了。</p>
<h3 id="上传"><a href="#上传" class="headerlink" title="上传"></a>上传</h3><p>github 本身提供了’Release’功能，每个仓库都有一个’Release’页面</p>
<p><img src="/images/QtActions2/1.png" alt=""></p>
<p>可以将打包好的压缩包或者安装包，直接上传上去, 供他人下载。</p>
<p><img src="/images/QtActions2/2.png" alt=""></p>
<p>github-Actions还提供了 创建’Release’、上传’Release’的模板</p>
<p><a href="https://github.com/actions/create-release" target="_blank" rel="noopener">actions/create-release</a></p>
<p><a href="https://github.com/actions/upload-release-asset" target="_blank" rel="noopener">actions/upload-release-asset</a></p>
<p>这两个模板的用法也很简单，在yml文件中直接use就行了，不赘述了。</p>
<h2 id="定制发布流程"><a href="#定制发布流程" class="headerlink" title="定制发布流程"></a>定制发布流程</h2><p>前面介绍了一些简单的理论，接下来通过实例，教大家github-Actions的使用。</p>
<p>以<a href="https://github.com/jaredtao/HelloActions-Qt" target="_blank" rel="noopener">HelloActions-Qt</a>项目为例，做一些定制。</p>
<p>需求如下：</p>
<p>1、每次提交代码，同时在Windows、MacOS、Ubuntu、Android、IOS五个平台编译</p>
<p>2、每次提交tag，在windows和MacOS平台制作软件包，并发布到同一个github-‘Release’</p>
<p>需求1已经实现了，着重讨论一下需求2：</p>
<h3 id="发布时机"><a href="#发布时机" class="headerlink" title="发布时机"></a>发布时机</h3><p>‘每次提交tag’限定了发布的时机。</p>
<p>涛哥尝试了一番，最终得到答案。</p>
<p>回顾一下, Windows平台的编译配置：</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">name:</span> <span class="string">Windows</span></span><br><span class="line"><span class="attr">on:</span> <span class="string">[push,pull_request]</span></span><br><span class="line"><span class="attr">jobs:</span></span><br><span class="line"><span class="attr">  build:</span></span><br><span class="line"><span class="attr">    name:</span> <span class="string">Build</span></span><br><span class="line"><span class="attr">    runs-on:</span> <span class="string">windows-latest</span></span><br><span class="line"><span class="attr">    strategy:</span></span><br><span class="line"><span class="attr">      matrix:</span></span><br><span class="line"><span class="attr">        qt_ver:</span> <span class="string">[5.12.6]</span></span><br><span class="line"><span class="attr">        qt_target:</span> <span class="string">[desktop]</span></span><br><span class="line"><span class="attr">        qt_arch:</span> <span class="string">[win64_msvc2017_64,</span> <span class="string">win32_msvc2017]</span></span><br><span class="line"><span class="attr">        include:</span></span><br><span class="line"><span class="attr">          - qt_arch:</span> <span class="string">win64_msvc2017_64</span></span><br><span class="line"><span class="attr">            msvc_arch:</span> <span class="string">x64</span></span><br><span class="line"><span class="attr">          - qt_arch:</span> <span class="string">win32_msvc2017</span></span><br><span class="line"><span class="attr">            msvc_arch:</span> <span class="string">x86</span></span><br><span class="line">    <span class="comment"># 步骤</span></span><br><span class="line"><span class="attr">    steps:</span></span><br><span class="line">      <span class="comment"># 安装Qt</span></span><br><span class="line"><span class="attr">      - name:</span> <span class="string">Install</span> <span class="string">Qt</span></span><br><span class="line"><span class="attr">        uses:</span> <span class="string">jurplel/install-qt-action@v2.0.0</span></span><br><span class="line"><span class="attr">        with:</span></span><br><span class="line"><span class="attr">          version:</span> <span class="string">$&#123;&#123;</span> <span class="string">matrix.qt_ver</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">          target:</span> <span class="string">$&#123;&#123;</span> <span class="string">matrix.qt_target</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">          arch:</span> <span class="string">$&#123;&#123;</span> <span class="string">matrix.qt_arch</span> <span class="string">&#125;&#125;</span></span><br><span class="line">      <span class="comment"># 拉取代码</span></span><br><span class="line"><span class="attr">      - uses:</span> <span class="string">actions/checkout@v1</span></span><br><span class="line"><span class="attr">        with:</span></span><br><span class="line"><span class="attr">          fetch-depth:</span> <span class="number">1</span></span><br><span class="line">      <span class="comment"># 编译msvc</span></span><br><span class="line"><span class="attr">      - name:</span> <span class="string">build-msvc</span></span><br><span class="line"><span class="attr">        shell:</span> <span class="string">cmd</span></span><br><span class="line"><span class="attr">        env:</span></span><br><span class="line"><span class="attr">          vc_arch:</span> <span class="string">$&#123;&#123;</span> <span class="string">matrix.msvc_arch</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">        run:</span> <span class="string">|</span></span><br><span class="line"><span class="string">          call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" %vc_arch%</span></span><br><span class="line"><span class="string">          qmake</span></span><br><span class="line"><span class="string">          nmake</span></span><br></pre></td></tr></table></figure>
<p>steps中的每一个步骤，可以有触发条件。我们可以在这里指定，只有github的事件为tag时才执行:</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">steps:</span></span><br><span class="line">  <span class="string">。。。</span></span><br><span class="line">  <span class="comment"># tag 打包</span></span><br><span class="line"><span class="attr">  - name:</span> <span class="string">package</span></span><br><span class="line"><span class="attr">    if:</span> <span class="string">startsWith(github.event.ref,</span> <span class="string">'refs/tags/'</span><span class="string">)</span></span><br><span class="line"><span class="attr">    run:</span> <span class="string">|</span></span><br><span class="line"><span class="string">      。。。</span></span><br></pre></td></tr></table></figure>
<h3 id="打包步骤"><a href="#打包步骤" class="headerlink" title="打包步骤"></a>打包步骤</h3><p>这里给出一个实际的打包步骤：</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># tag 打包</span></span><br><span class="line"><span class="attr">- name:</span> <span class="string">package</span></span><br><span class="line"><span class="attr">  if:</span> <span class="string">startsWith(github.event.ref,</span> <span class="string">'refs/tags/'</span><span class="string">)</span></span><br><span class="line"><span class="attr">  env:</span></span><br><span class="line"><span class="attr">    VCINSTALLDIR:</span> <span class="string">'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC'</span></span><br><span class="line"><span class="attr">    archiveName:</span> <span class="string">$&#123;&#123;</span> <span class="string">matrix.qt_ver</span> <span class="string">&#125;&#125;-$&#123;&#123;</span> <span class="string">matrix.qt_target</span> <span class="string">&#125;&#125;-$&#123;&#123;</span> <span class="string">matrix.qt_arch</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">    targetName:</span> <span class="string">HelloActions-Qt.exe</span></span><br><span class="line"><span class="attr">  shell:</span> <span class="string">pwsh</span></span><br><span class="line"><span class="attr">  run:</span> <span class="string">|</span></span><br><span class="line"><span class="string">    # 创建文件夹</span></span><br><span class="line"><span class="string">    New-Item -ItemType Directory $&#123;env:archiveName&#125;</span></span><br><span class="line"><span class="string">    # 拷贝exe</span></span><br><span class="line"><span class="string">    Copy-Item bin\$&#123;env:targetName&#125; $&#123;env:archiveName&#125;\</span></span><br><span class="line"><span class="string">    # 拷贝依赖</span></span><br><span class="line"><span class="string">    windeployqt --qmldir . $&#123;env:archiveName&#125;\$&#123;env:targetName&#125;</span></span><br><span class="line"><span class="string">    # 打包zip</span></span><br><span class="line"><span class="string">    Compress-Archive -Path $&#123;env:archiveName&#125; $&#123;env:archiveName&#125;'.zip'</span></span><br><span class="line"><span class="string">    # 记录环境变量packageName给后续step</span></span><br><span class="line"><span class="string">    $name = $&#123;env:archiveName&#125;</span></span><br><span class="line"><span class="string">    echo "::set-env name=packageName::$name"</span></span><br><span class="line"><span class="string">    # 打印环境变量packageName</span></span><br><span class="line"><span class="string">    Write-Host 'packageName:'$&#123;env:packageName&#125;</span></span><br></pre></td></tr></table></figure>
<p>做一些说明：</p>
<ul>
<li>vs运行时</li>
</ul>
<p>其中的VCINSTALLDIR环境变量，是给windeployqt用的。有了这个环境变量，windeployqt会去msvc的安装路径提取‘运行时安装程序’。</p>
<ul>
<li>记录包名称</li>
</ul>
<p>打包完以后，将包名设置为环境变量，后续的步骤就可以通过环境变量拿到包名字了。</p>
<p>普通的设置环境变量，在步骤执行完成后就失效了，</p>
<p>这里使用github-Actions的‘记录命令’set-env ，具体可以参考文档<a href="https://help.github.com/zh/actions/automating-your-workflow-with-github-actions/development-tools-for-github-actions" target="_blank" rel="noopener">github-Actions记录命令</a>         </p>
<p>文档说不要用双引号，应该都是针对linux的，我试出来的PowerShell用法如下：</p>
<figure class="highlight powershell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="variable">$name</span> = $&#123;env:archiveName&#125;</span><br><span class="line">echo <span class="string">"::set-env name=packageName::<span class="variable">$name</span>"</span></span><br></pre></td></tr></table></figure>

<p>先取环境变量到一个局部变量，再在‘记录命令’中引用局部变量。</p>
<h3 id="多平台发布"><a href="#多平台发布" class="headerlink" title="多平台发布"></a>多平台发布</h3><p>如果只有一个平台、一种配置，直接用那两个模板就能解决问题。</p>
<p>这是官方给的例子<a href="https://github.com/actions/upload-release-asset" target="_blank" rel="noopener">upload-release-asset</a>：</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">steps:</span></span><br><span class="line"><span class="attr">  - name:</span> <span class="string">Checkout</span> <span class="string">code</span></span><br><span class="line"><span class="attr">    uses:</span> <span class="string">actions/checkout@master</span></span><br><span class="line"><span class="attr">  - name:</span> <span class="string">Build</span> <span class="string">project</span> <span class="comment"># This would actually build your project, using zip for an example artifact</span></span><br><span class="line"><span class="attr">    run:</span> <span class="string">|</span></span><br><span class="line"><span class="string">      zip --junk-paths my-artifact README.md</span></span><br><span class="line"><span class="string"></span><span class="attr">  - name:</span> <span class="string">Create</span> <span class="string">Release</span></span><br><span class="line"><span class="attr">    id:</span> <span class="string">create_release</span></span><br><span class="line"><span class="attr">    uses:</span> <span class="string">actions/create-release@v1.0.0</span></span><br><span class="line"><span class="attr">    env:</span></span><br><span class="line"><span class="attr">      GITHUB_TOKEN:</span> <span class="string">$&#123;&#123;</span> <span class="string">secrets.GITHUB_TOKEN</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">    with:</span></span><br><span class="line"><span class="attr">      tag_name:</span> <span class="string">$&#123;&#123;</span> <span class="string">github.ref</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">      release_name:</span> <span class="string">Release</span> <span class="string">$&#123;&#123;</span> <span class="string">github.ref</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">      draft:</span> <span class="literal">false</span></span><br><span class="line"><span class="attr">      prerelease:</span> <span class="literal">false</span></span><br><span class="line"><span class="attr">  - name:</span> <span class="string">Upload</span> <span class="string">Release</span> <span class="string">Asset</span></span><br><span class="line"><span class="attr">    id:</span> <span class="string">upload-release-asset</span> </span><br><span class="line"><span class="attr">    uses:</span> <span class="string">actions/upload-release-asset@v1.0.1</span></span><br><span class="line"><span class="attr">    env:</span></span><br><span class="line"><span class="attr">      GITHUB_TOKEN:</span> <span class="string">$&#123;&#123;</span> <span class="string">secrets.GITHUB_TOKEN</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">    with:</span></span><br><span class="line"><span class="attr">      upload_url:</span> <span class="string">$&#123;&#123;</span> <span class="string">steps.create_release.outputs.upload_url</span> <span class="string">&#125;&#125;</span> <span class="comment"># This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps </span></span><br><span class="line"><span class="attr">      asset_path:</span> <span class="string">./my-artifact.zip</span></span><br><span class="line"><span class="attr">      asset_name:</span> <span class="string">my-artifact.zip</span></span><br><span class="line"><span class="attr">      asset_content_type:</span> <span class="string">application/zip</span></span><br></pre></td></tr></table></figure>

<p>在多平台 或者 多配置的情况下，同一个tag, 只有第一个执行create-release的任务可以成功，后续任务</p>
<p>再次执行create-release时，该tag下已经有了同名的‘Release’，所以会create失败。</p>
<p>这个问题折磨了涛哥好一阵子。找不到现成的解决方案，涛哥就自己实现了一种:</p>
<ol>
<li><p>先用github的REST API去判断该tag下有没有‘Release’:</p>
<p> 没有则执行create-release，并提取upload_url；</p>
<p> 有则提取upload_url。</p>
</li>
<li><p>最后执行upload-release-asset </p>
</li>
</ol>
<p>调用REST API，涛哥依旧使用了方便的PowerShell,</p>
<p>实际的配置如下：</p>
<figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># tag 查询github-Release</span></span><br><span class="line"><span class="attr">- name:</span> <span class="string">queryReleaseWin</span></span><br><span class="line"><span class="attr">  id:</span> <span class="string">queryReleaseWin</span></span><br><span class="line"><span class="attr">  if:</span> <span class="string">startsWith(github.event.ref,</span> <span class="string">'refs/tags/'</span><span class="string">)</span></span><br><span class="line"><span class="attr">  shell:</span> <span class="string">pwsh</span></span><br><span class="line"><span class="attr">  env:</span></span><br><span class="line"><span class="attr">    githubFullName:</span> <span class="string">$&#123;&#123;</span> <span class="string">github.event.repository.full_name</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">    ref:</span> <span class="string">$&#123;&#123;</span> <span class="string">github.event.ref</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">  run:</span> <span class="string">|</span></span><br><span class="line"><span class="string">    [string]$tag = $&#123;env:ref&#125;.Substring($&#123;env:ref&#125;.LastIndexOf('/') + 1)</span></span><br><span class="line"><span class="string">    [string]$url = 'https://api.github.com/repos/' + $&#123;env:githubFullName&#125; + '/releases/tags/' + $&#123;tag&#125;</span></span><br><span class="line"><span class="string">    $response=&#123;&#125;</span></span><br><span class="line"><span class="string">    try &#123;</span></span><br><span class="line"><span class="string">      $response = Invoke-RestMethod -Uri $url -Method Get</span></span><br><span class="line"><span class="string">    &#125; catch &#123;</span></span><br><span class="line"><span class="string">      Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__ </span></span><br><span class="line"><span class="string">      Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription</span></span><br><span class="line"><span class="string">      # 没查到，输出</span></span><br><span class="line"><span class="string">      echo "::set-output name=needCreateRelease::true"  </span></span><br><span class="line"><span class="string">      return</span></span><br><span class="line"><span class="string">    &#125;</span></span><br><span class="line"><span class="string">    [string]$latestUpUrl = $response.upload_url</span></span><br><span class="line"><span class="string">    Write-Host 'latestUpUrl:'$latestUpUrl</span></span><br><span class="line"><span class="string">    if ($latestUpUrl.Length -eq 0) &#123;</span></span><br><span class="line"><span class="string">      # 没查到，输出</span></span><br><span class="line"><span class="string">      echo "::set-output name=needCreateRelease::true"  </span></span><br><span class="line"><span class="string">    &#125;</span></span><br><span class="line"><span class="string"># tag 创建github-Release</span></span><br><span class="line"><span class="string"></span><span class="attr">- name:</span> <span class="string">createReleaseWin</span></span><br><span class="line"><span class="attr">  id:</span> <span class="string">createReleaseWin</span></span><br><span class="line"><span class="attr">  if:</span> <span class="string">startsWith(github.event.ref,</span> <span class="string">'refs/tags/'</span><span class="string">)</span> <span class="string">&amp;&amp;</span> <span class="string">steps.queryReleaseWin.outputs.needCreateRelease</span> <span class="string">==</span> <span class="string">'true'</span></span><br><span class="line"><span class="attr">  env:</span></span><br><span class="line"><span class="attr">    GITHUB_TOKEN:</span> <span class="string">$&#123;&#123;</span> <span class="string">secrets.GITHUB_TOKEN</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">  uses:</span> <span class="string">actions/create-release@v1.0.0</span></span><br><span class="line"><span class="attr">  with:</span></span><br><span class="line"><span class="attr">    tag_name:</span> <span class="string">$&#123;&#123;</span> <span class="string">github.ref</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">    release_name:</span> <span class="string">Release</span> <span class="string">$&#123;&#123;</span> <span class="string">github.ref</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">    body:</span> <span class="string">$&#123;&#123;</span> <span class="string">github.event.head_commit.message</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">    draft:</span> <span class="literal">false</span></span><br><span class="line"><span class="attr">    prerelease:</span> <span class="literal">false</span></span><br><span class="line"><span class="comment"># tag 重定向upload_url到环境变量uploadUrl。</span></span><br><span class="line"><span class="attr">- name:</span> <span class="string">getLatestTagRelease</span></span><br><span class="line"><span class="attr">  if:</span> <span class="string">startsWith(github.event.ref,</span> <span class="string">'refs/tags/'</span><span class="string">)</span></span><br><span class="line"><span class="attr">  shell:</span> <span class="string">pwsh</span></span><br><span class="line"><span class="attr">  env:</span></span><br><span class="line"><span class="attr">    githubFullName:</span> <span class="string">$&#123;&#123;</span> <span class="string">github.event.repository.full_name</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">    upUrl:</span> <span class="string">$&#123;&#123;</span> <span class="string">steps.createReleaseWin.outputs.upload_url</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">    ref:</span> <span class="string">$&#123;&#123;</span> <span class="string">github.event.ref</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">  run:</span> <span class="string">|</span></span><br><span class="line"><span class="string">    # upUrl不为空，导出就完事</span></span><br><span class="line"><span class="string">    if ($&#123;env:upUrl&#125;.Length -gt 0) &#123;</span></span><br><span class="line"><span class="string">        $v=$&#123;env:upUrl&#125;</span></span><br><span class="line"><span class="string">        echo "::set-env name=uploadUrl::$v"</span></span><br><span class="line"><span class="string">        return</span></span><br><span class="line"><span class="string">    &#125; </span></span><br><span class="line"><span class="string">    # upUrl为空则重新获取</span></span><br><span class="line"><span class="string">    [string]$tag = $&#123;env:ref&#125;.Substring($&#123;env:ref&#125;.LastIndexOf('/') + 1)</span></span><br><span class="line"><span class="string">    [string]$url = 'https://api.github.com/repos/' + $&#123;env:githubFullName&#125; + '/releases/tags/' + $&#123;tag&#125;</span></span><br><span class="line"><span class="string">    $response = Invoke-RestMethod -Uri $url -Method Get</span></span><br><span class="line"><span class="string">    [string]$latestUpUrl = $response.upload_url</span></span><br><span class="line"><span class="string">    Write-Host 'latestUpUrl:'$latestUpUrl</span></span><br><span class="line"><span class="string">    # 导出</span></span><br><span class="line"><span class="string">    echo "::set-env name=uploadUrl::$latestUpUrl"</span></span><br><span class="line"><span class="string">    Write-Host 'env uploadUrl:'$&#123;env:uploadUrl&#125;</span></span><br><span class="line"><span class="string"># tag 上传Release</span></span><br><span class="line"><span class="string"></span><span class="attr">- name:</span> <span class="string">uploadRelease</span></span><br><span class="line"><span class="attr">  id:</span> <span class="string">uploadRelease</span></span><br><span class="line"><span class="attr">  if:</span> <span class="string">startsWith(github.event.ref,</span> <span class="string">'refs/tags/'</span><span class="string">)</span></span><br><span class="line"><span class="attr">  env:</span></span><br><span class="line"><span class="attr">    GITHUB_TOKEN:</span> <span class="string">$&#123;&#123;</span> <span class="string">secrets.GITHUB_TOKEN</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">  uses:</span> <span class="string">actions/upload-release-asset@v1.0.1</span></span><br><span class="line"><span class="attr">  with:</span></span><br><span class="line"><span class="attr">    upload_url:</span> <span class="string">$&#123;&#123;</span> <span class="string">env.uploadUrl</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">    asset_path:</span> <span class="string">./$&#123;&#123;</span> <span class="string">env.packageName</span> <span class="string">&#125;&#125;.zip</span></span><br><span class="line"><span class="attr">    asset_name:</span> <span class="string">$&#123;&#123;</span> <span class="string">env.packageName</span> <span class="string">&#125;&#125;.zip</span></span><br><span class="line"><span class="attr">    asset_content_type:</span> <span class="string">application/zip</span></span><br></pre></td></tr></table></figure>
<h3 id="最终配置"><a href="#最终配置" class="headerlink" title="最终配置"></a>最终配置</h3><h4 id="windows版的最终配置"><a href="#windows版的最终配置" class="headerlink" title="windows版的最终配置"></a>windows版的最终配置</h4><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">name:</span> <span class="string">Windows</span></span><br><span class="line"><span class="attr">on:</span> </span><br><span class="line">  <span class="comment"># push代码时触发workflow</span></span><br><span class="line"><span class="attr">  push:</span></span><br><span class="line">    <span class="comment"># 忽略README.md</span></span><br><span class="line"><span class="attr">    paths-ignore:</span></span><br><span class="line"><span class="bullet">      -</span> <span class="string">'README.md'</span></span><br><span class="line"><span class="bullet">      -</span> <span class="string">'LICENSE'</span></span><br><span class="line">  <span class="comment"># pull_request时触发workflow</span></span><br><span class="line"><span class="attr">  pull_request:</span></span><br><span class="line">    <span class="comment"># 忽略README.md</span></span><br><span class="line"><span class="attr">    paths-ignore:</span></span><br><span class="line"><span class="bullet">      -</span> <span class="string">'README.md'</span></span><br><span class="line"><span class="bullet">      -</span> <span class="string">'LICENSE'</span></span><br><span class="line"><span class="attr">jobs:</span></span><br><span class="line"><span class="attr">  build:</span></span><br><span class="line"><span class="attr">    name:</span> <span class="string">Build</span></span><br><span class="line">    <span class="comment"># 运行平台， windows-latest目前是windows server 2019</span></span><br><span class="line"><span class="attr">    runs-on:</span> <span class="string">windows-latest</span></span><br><span class="line"><span class="attr">    strategy:</span></span><br><span class="line">      <span class="comment"># 矩阵配置</span></span><br><span class="line"><span class="attr">      matrix:</span></span><br><span class="line"><span class="attr">        qt_ver:</span> <span class="string">[5.12.6]</span></span><br><span class="line"><span class="attr">        qt_target:</span> <span class="string">[desktop]</span></span><br><span class="line"><span class="attr">        qt_arch:</span> <span class="string">[win64_msvc2017_64,</span> <span class="string">win32_msvc2017]</span></span><br><span class="line">        <span class="comment"># 额外设置msvc_arch</span></span><br><span class="line"><span class="attr">        include:</span></span><br><span class="line"><span class="attr">          - qt_arch:</span> <span class="string">win64_msvc2017_64</span></span><br><span class="line"><span class="attr">            msvc_arch:</span> <span class="string">x64</span></span><br><span class="line"><span class="attr">            qt_arch_install:</span> <span class="string">msvc2017_64</span></span><br><span class="line"><span class="attr">          - qt_arch:</span> <span class="string">win32_msvc2017</span></span><br><span class="line"><span class="attr">            msvc_arch:</span> <span class="string">x86</span></span><br><span class="line"><span class="attr">            qt_arch_install:</span> <span class="string">msvc2017</span></span><br><span class="line"><span class="attr">    env:</span></span><br><span class="line"><span class="attr">      targetName:</span> <span class="string">HelloActions-Qt.exe</span></span><br><span class="line">    <span class="comment"># 步骤</span></span><br><span class="line"><span class="attr">    steps:</span>  </span><br><span class="line">      <span class="comment"># 安装Qt</span></span><br><span class="line"><span class="attr">      - name:</span> <span class="string">Install</span> <span class="string">Qt</span></span><br><span class="line">        <span class="comment"># 使用外部action。这个action专门用来安装Qt</span></span><br><span class="line"><span class="attr">        uses:</span> <span class="string">jurplel/install-qt-action@v2.0.0</span></span><br><span class="line"><span class="attr">        with:</span></span><br><span class="line">          <span class="comment"># Version of Qt to install</span></span><br><span class="line"><span class="attr">          version:</span> <span class="string">$&#123;&#123;</span> <span class="string">matrix.qt_ver</span> <span class="string">&#125;&#125;</span></span><br><span class="line">          <span class="comment"># Target platform for build</span></span><br><span class="line"><span class="attr">          target:</span> <span class="string">$&#123;&#123;</span> <span class="string">matrix.qt_target</span> <span class="string">&#125;&#125;</span></span><br><span class="line">          <span class="comment"># Architecture for Windows/Android</span></span><br><span class="line"><span class="attr">          arch:</span> <span class="string">$&#123;&#123;</span> <span class="string">matrix.qt_arch</span> <span class="string">&#125;&#125;</span></span><br><span class="line">      <span class="comment"># 拉取代码</span></span><br><span class="line"><span class="attr">      - uses:</span> <span class="string">actions/checkout@v1</span></span><br><span class="line"><span class="attr">        with:</span></span><br><span class="line"><span class="attr">          fetch-depth:</span> <span class="number">1</span></span><br><span class="line">      <span class="comment"># 编译msvc</span></span><br><span class="line"><span class="attr">      - name:</span> <span class="string">build-msvc</span></span><br><span class="line"><span class="attr">        shell:</span> <span class="string">cmd</span></span><br><span class="line"><span class="attr">        env:</span></span><br><span class="line"><span class="attr">          vc_arch:</span> <span class="string">$&#123;&#123;</span> <span class="string">matrix.msvc_arch</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">        run:</span> <span class="string">|</span></span><br><span class="line"><span class="string">          call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" %vc_arch%</span></span><br><span class="line"><span class="string">          qmake</span></span><br><span class="line"><span class="string">          nmake</span></span><br><span class="line"><span class="string">      # tag 打包</span></span><br><span class="line"><span class="string"></span><span class="attr">      - name:</span> <span class="string">package</span></span><br><span class="line"><span class="attr">        if:</span> <span class="string">startsWith(github.event.ref,</span> <span class="string">'refs/tags/'</span><span class="string">)</span></span><br><span class="line"><span class="attr">        env:</span></span><br><span class="line"><span class="attr">          VCINSTALLDIR:</span> <span class="string">'C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC'</span></span><br><span class="line"><span class="attr">          archiveName:</span> <span class="string">$&#123;&#123;</span> <span class="string">matrix.qt_ver</span> <span class="string">&#125;&#125;-$&#123;&#123;</span> <span class="string">matrix.qt_target</span> <span class="string">&#125;&#125;-$&#123;&#123;</span> <span class="string">matrix.qt_arch</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">        shell:</span> <span class="string">pwsh</span></span><br><span class="line"><span class="attr">        run:</span> <span class="string">|</span></span><br><span class="line"><span class="string">          # 创建文件夹</span></span><br><span class="line"><span class="string">          New-Item -ItemType Directory $&#123;env:archiveName&#125;</span></span><br><span class="line"><span class="string">          # 拷贝exe</span></span><br><span class="line"><span class="string">          Copy-Item bin\$&#123;env:targetName&#125; $&#123;env:archiveName&#125;\</span></span><br><span class="line"><span class="string">          # 拷贝依赖</span></span><br><span class="line"><span class="string">          windeployqt --qmldir . $&#123;env:archiveName&#125;\$&#123;env:targetName&#125;</span></span><br><span class="line"><span class="string">          # 打包zip</span></span><br><span class="line"><span class="string">          Compress-Archive -Path $&#123;env:archiveName&#125; $&#123;env:archiveName&#125;'.zip'</span></span><br><span class="line"><span class="string">          # 记录环境变量packageName给后续step</span></span><br><span class="line"><span class="string">          $name = $&#123;env:archiveName&#125;</span></span><br><span class="line"><span class="string">          echo "::set-env name=packageName::$name"</span></span><br><span class="line"><span class="string">          # 打印环境变量packageName</span></span><br><span class="line"><span class="string">          Write-Host 'packageName:'$&#123;env:packageName&#125;</span></span><br><span class="line"><span class="string">      # tag 查询github-Release</span></span><br><span class="line"><span class="string"></span><span class="attr">      - name:</span> <span class="string">queryReleaseWin</span></span><br><span class="line"><span class="attr">        id:</span> <span class="string">queryReleaseWin</span></span><br><span class="line"><span class="attr">        if:</span> <span class="string">startsWith(github.event.ref,</span> <span class="string">'refs/tags/'</span><span class="string">)</span></span><br><span class="line"><span class="attr">        shell:</span> <span class="string">pwsh</span></span><br><span class="line"><span class="attr">        env:</span></span><br><span class="line"><span class="attr">          githubFullName:</span> <span class="string">$&#123;&#123;</span> <span class="string">github.event.repository.full_name</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">          ref:</span> <span class="string">$&#123;&#123;</span> <span class="string">github.event.ref</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">        run:</span> <span class="string">|</span></span><br><span class="line"><span class="string">          [string]$tag = $&#123;env:ref&#125;.Substring($&#123;env:ref&#125;.LastIndexOf('/') + 1)</span></span><br><span class="line"><span class="string">          [string]$url = 'https://api.github.com/repos/' + $&#123;env:githubFullName&#125; + '/releases/tags/' + $&#123;tag&#125;</span></span><br><span class="line"><span class="string">          $response=&#123;&#125;</span></span><br><span class="line"><span class="string">          try &#123;</span></span><br><span class="line"><span class="string">            $response = Invoke-RestMethod -Uri $url -Method Get</span></span><br><span class="line"><span class="string">          &#125; catch &#123;</span></span><br><span class="line"><span class="string">            Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__ </span></span><br><span class="line"><span class="string">            Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription</span></span><br><span class="line"><span class="string">            # 没查到，输出</span></span><br><span class="line"><span class="string">            echo "::set-output name=needCreateRelease::true"  </span></span><br><span class="line"><span class="string">            return</span></span><br><span class="line"><span class="string">          &#125;</span></span><br><span class="line"><span class="string">          [string]$latestUpUrl = $response.upload_url</span></span><br><span class="line"><span class="string">          Write-Host 'latestUpUrl:'$latestUpUrl</span></span><br><span class="line"><span class="string">          if ($latestUpUrl.Length -eq 0) &#123;</span></span><br><span class="line"><span class="string">            # 没查到，输出</span></span><br><span class="line"><span class="string">            echo "::set-output name=needCreateRelease::true"  </span></span><br><span class="line"><span class="string">          &#125;</span></span><br><span class="line"><span class="string">      # tag 创建github-Release</span></span><br><span class="line"><span class="string"></span><span class="attr">      - name:</span> <span class="string">createReleaseWin</span></span><br><span class="line"><span class="attr">        id:</span> <span class="string">createReleaseWin</span></span><br><span class="line"><span class="attr">        if:</span> <span class="string">startsWith(github.event.ref,</span> <span class="string">'refs/tags/'</span><span class="string">)</span> <span class="string">&amp;&amp;</span> <span class="string">steps.queryReleaseWin.outputs.needCreateRelease</span> <span class="string">==</span> <span class="string">'true'</span></span><br><span class="line"><span class="attr">        env:</span></span><br><span class="line"><span class="attr">          GITHUB_TOKEN:</span> <span class="string">$&#123;&#123;</span> <span class="string">secrets.GITHUB_TOKEN</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">        uses:</span> <span class="string">actions/create-release@v1.0.0</span></span><br><span class="line"><span class="attr">        with:</span></span><br><span class="line"><span class="attr">          tag_name:</span> <span class="string">$&#123;&#123;</span> <span class="string">github.ref</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">          release_name:</span> <span class="string">Release</span> <span class="string">$&#123;&#123;</span> <span class="string">github.ref</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">          body:</span> <span class="string">$&#123;&#123;</span> <span class="string">github.event.head_commit.message</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">          draft:</span> <span class="literal">false</span></span><br><span class="line"><span class="attr">          prerelease:</span> <span class="literal">false</span></span><br><span class="line">      <span class="comment"># 重定向upload_url到环境变量uploadUrl。</span></span><br><span class="line"><span class="attr">      - name:</span> <span class="string">getLatestTagRelease</span></span><br><span class="line">        <span class="comment"># tag 上一步无论成功还是失败都执行</span></span><br><span class="line"><span class="attr">        if:</span> <span class="string">startsWith(github.event.ref,</span> <span class="string">'refs/tags/'</span><span class="string">)</span></span><br><span class="line"><span class="attr">        shell:</span> <span class="string">pwsh</span></span><br><span class="line"><span class="attr">        env:</span></span><br><span class="line"><span class="attr">          githubFullName:</span> <span class="string">$&#123;&#123;</span> <span class="string">github.event.repository.full_name</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">          upUrl:</span> <span class="string">$&#123;&#123;</span> <span class="string">steps.createReleaseWin.outputs.upload_url</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">          ref:</span> <span class="string">$&#123;&#123;</span> <span class="string">github.event.ref</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">        run:</span> <span class="string">|</span></span><br><span class="line"><span class="string">          # upUrl不为空，导出就完事</span></span><br><span class="line"><span class="string">          if ($&#123;env:upUrl&#125;.Length -gt 0) &#123;</span></span><br><span class="line"><span class="string">              $v=$&#123;env:upUrl&#125;</span></span><br><span class="line"><span class="string">              echo "::set-env name=uploadUrl::$v"</span></span><br><span class="line"><span class="string">              return</span></span><br><span class="line"><span class="string">          &#125; </span></span><br><span class="line"><span class="string">          [string]$tag = $&#123;env:ref&#125;.Substring($&#123;env:ref&#125;.LastIndexOf('/') + 1)</span></span><br><span class="line"><span class="string">          [string]$url = 'https://api.github.com/repos/' + $&#123;env:githubFullName&#125; + '/releases/tags/' + $&#123;tag&#125;</span></span><br><span class="line"><span class="string">          $response = Invoke-RestMethod -Uri $url -Method Get</span></span><br><span class="line"><span class="string">          [string]$latestUpUrl = $response.upload_url</span></span><br><span class="line"><span class="string">          Write-Host 'latestUpUrl:'$latestUpUrl</span></span><br><span class="line"><span class="string">          echo "::set-env name=uploadUrl::$latestUpUrl"</span></span><br><span class="line"><span class="string">          Write-Host 'env uploadUrl:'$&#123;env:uploadUrl&#125;</span></span><br><span class="line"><span class="string">      # tag 上传Release</span></span><br><span class="line"><span class="string"></span><span class="attr">      - name:</span> <span class="string">uploadRelease</span></span><br><span class="line"><span class="attr">        id:</span> <span class="string">uploadRelease</span></span><br><span class="line"><span class="attr">        if:</span> <span class="string">startsWith(github.event.ref,</span> <span class="string">'refs/tags/'</span><span class="string">)</span></span><br><span class="line"><span class="attr">        env:</span></span><br><span class="line"><span class="attr">          GITHUB_TOKEN:</span> <span class="string">$&#123;&#123;</span> <span class="string">secrets.GITHUB_TOKEN</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">        uses:</span> <span class="string">actions/upload-release-asset@v1.0.1</span></span><br><span class="line"><span class="attr">        with:</span></span><br><span class="line"><span class="attr">          upload_url:</span> <span class="string">$&#123;&#123;</span> <span class="string">env.uploadUrl</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">          asset_path:</span> <span class="string">./$&#123;&#123;</span> <span class="string">env.packageName</span> <span class="string">&#125;&#125;.zip</span></span><br><span class="line"><span class="attr">          asset_name:</span> <span class="string">$&#123;&#123;</span> <span class="string">env.packageName</span> <span class="string">&#125;&#125;.zip</span></span><br><span class="line"><span class="attr">          asset_content_type:</span> <span class="string">application/zip</span></span><br></pre></td></tr></table></figure>

<h4 id="MacOS最终配置"><a href="#MacOS最终配置" class="headerlink" title="MacOS最终配置"></a>MacOS最终配置</h4><figure class="highlight yml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br></pre></td><td class="code"><pre><span class="line"><span class="attr">name:</span> <span class="string">MacOS</span></span><br><span class="line"><span class="attr">on:</span> </span><br><span class="line"><span class="attr">  push:</span></span><br><span class="line"><span class="attr">    paths-ignore:</span></span><br><span class="line"><span class="bullet">      -</span> <span class="string">'README.md'</span></span><br><span class="line"><span class="bullet">      -</span> <span class="string">'LICENSE'</span></span><br><span class="line"><span class="attr">  pull_request:</span></span><br><span class="line"><span class="attr">    paths-ignore:</span></span><br><span class="line"><span class="bullet">      -</span> <span class="string">'README.md'</span></span><br><span class="line"><span class="bullet">      -</span> <span class="string">'LICENSE'</span></span><br><span class="line"><span class="attr">jobs:</span></span><br><span class="line"><span class="attr">  build:</span></span><br><span class="line"><span class="attr">    name:</span> <span class="string">Build</span></span><br><span class="line"><span class="attr">    runs-on:</span> <span class="string">$&#123;&#123;</span> <span class="string">matrix.os</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">    strategy:</span></span><br><span class="line"><span class="attr">      matrix:</span></span><br><span class="line"><span class="attr">        os:</span> <span class="string">[macos-latest]</span></span><br><span class="line"><span class="attr">        qt_ver:</span> <span class="string">[5.12.6]</span></span><br><span class="line"><span class="attr">        qt_arch:</span> <span class="string">[clang_64]</span></span><br><span class="line"><span class="attr">    env:</span></span><br><span class="line"><span class="attr">      targetName:</span> <span class="string">HelloActions-Qt</span></span><br><span class="line"><span class="attr">    steps:</span></span><br><span class="line"><span class="attr">      - name:</span> <span class="string">Install</span> <span class="string">Qt</span></span><br><span class="line"><span class="attr">        uses:</span> <span class="string">jurplel/install-qt-action@v2.0.0</span></span><br><span class="line"><span class="attr">        with:</span></span><br><span class="line"><span class="attr">          version:</span> <span class="string">$&#123;&#123;</span> <span class="string">matrix.qt_ver</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">      - uses:</span> <span class="string">actions/checkout@v1</span></span><br><span class="line"><span class="attr">        with:</span></span><br><span class="line"><span class="attr">          fetch-depth:</span> <span class="number">1</span></span><br><span class="line"><span class="attr">      - name:</span> <span class="string">build</span> <span class="string">macos</span></span><br><span class="line"><span class="attr">        run:</span> <span class="string">|</span></span><br><span class="line"><span class="string">          qmake</span></span><br><span class="line"><span class="string">          make</span></span><br><span class="line"><span class="string">      # tag 打包</span></span><br><span class="line"><span class="string"></span><span class="attr">      - name:</span> <span class="string">package</span></span><br><span class="line"><span class="attr">        if:</span> <span class="string">startsWith(github.event.ref,</span> <span class="string">'refs/tags/'</span><span class="string">)</span></span><br><span class="line"><span class="attr">        run:</span> <span class="string">|</span></span><br><span class="line"><span class="string">          # 拷贝依赖</span></span><br><span class="line"><span class="string">          macdeployqt bin/$&#123;targetName&#125;.app -qmldir=. -verbose=1 -dmg</span></span><br><span class="line"><span class="string">      # tag 查询github-Release</span></span><br><span class="line"><span class="string"></span><span class="attr">      - name:</span> <span class="string">queryRelease</span></span><br><span class="line"><span class="attr">        id:</span> <span class="string">queryReleaseMacos</span></span><br><span class="line"><span class="attr">        if:</span> <span class="string">startsWith(github.event.ref,</span> <span class="string">'refs/tags/'</span><span class="string">)</span></span><br><span class="line"><span class="attr">        shell:</span> <span class="string">pwsh</span></span><br><span class="line"><span class="attr">        env:</span></span><br><span class="line"><span class="attr">          githubFullName:</span> <span class="string">$&#123;&#123;</span> <span class="string">github.event.repository.full_name</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">          ref:</span> <span class="string">$&#123;&#123;</span> <span class="string">github.event.ref</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">        run:</span> <span class="string">|</span></span><br><span class="line"><span class="string">          [string]$tag = $&#123;env:ref&#125;.Substring($&#123;env:ref&#125;.LastIndexOf('/') + 1)</span></span><br><span class="line"><span class="string">          [string]$url = 'https://api.github.com/repos/' + $&#123;env:githubFullName&#125; + '/releases/tags/' + $&#123;tag&#125;</span></span><br><span class="line"><span class="string">          $response=&#123;&#125;</span></span><br><span class="line"><span class="string">          try &#123;</span></span><br><span class="line"><span class="string">            $response = Invoke-RestMethod -Uri $url -Method Get</span></span><br><span class="line"><span class="string">          &#125; catch &#123;</span></span><br><span class="line"><span class="string">            Write-Host "StatusCode:" $_.Exception.Response.StatusCode.value__ </span></span><br><span class="line"><span class="string">            Write-Host "StatusDescription:" $_.Exception.Response.StatusDescription</span></span><br><span class="line"><span class="string">            # 没查到，输出</span></span><br><span class="line"><span class="string">            echo "::set-output name=needCreateRelease::true"  </span></span><br><span class="line"><span class="string">            return</span></span><br><span class="line"><span class="string">          &#125;</span></span><br><span class="line"><span class="string">          [string]$latestUpUrl = $response.upload_url</span></span><br><span class="line"><span class="string">          Write-Host 'latestUpUrl:'$latestUpUrl</span></span><br><span class="line"><span class="string">          if ($latestUpUrl.Length -eq 0) &#123;</span></span><br><span class="line"><span class="string">            # 没查到，输出</span></span><br><span class="line"><span class="string">            echo "::set-output name=needCreateRelease::true"  </span></span><br><span class="line"><span class="string">          &#125;</span></span><br><span class="line"><span class="string">      # tag 创建github-Release</span></span><br><span class="line"><span class="string"></span><span class="attr">      - name:</span> <span class="string">createReleaseWin</span></span><br><span class="line"><span class="attr">        id:</span> <span class="string">createReleaseWin</span></span><br><span class="line"><span class="attr">        if:</span> <span class="string">startsWith(github.event.ref,</span> <span class="string">'refs/tags/'</span><span class="string">)</span> <span class="string">&amp;&amp;</span> <span class="string">steps.queryReleaseMacos.outputs.needCreateRelease</span> <span class="string">==</span> <span class="string">'true'</span></span><br><span class="line"><span class="attr">        env:</span></span><br><span class="line"><span class="attr">          GITHUB_TOKEN:</span> <span class="string">$&#123;&#123;</span> <span class="string">secrets.GITHUB_TOKEN</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">        uses:</span> <span class="string">actions/create-release@v1.0.0</span></span><br><span class="line"><span class="attr">        with:</span></span><br><span class="line"><span class="attr">          tag_name:</span> <span class="string">$&#123;&#123;</span> <span class="string">github.ref</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">          release_name:</span> <span class="string">Release</span> <span class="string">$&#123;&#123;</span> <span class="string">github.ref</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">          body:</span> <span class="string">$&#123;&#123;</span> <span class="string">github.event.head_commit.message</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">          draft:</span> <span class="literal">false</span></span><br><span class="line"><span class="attr">          prerelease:</span> <span class="literal">false</span></span><br><span class="line">      <span class="comment"># 重定向upload_url到环境变量uploadUrl。</span></span><br><span class="line"><span class="attr">      - name:</span> <span class="string">getLatestTagRelease</span></span><br><span class="line">        <span class="comment"># tag 上一步无论成功还是失败都执行</span></span><br><span class="line"><span class="attr">        if:</span> <span class="string">startsWith(github.event.ref,</span> <span class="string">'refs/tags/'</span><span class="string">)</span></span><br><span class="line"><span class="attr">        shell:</span> <span class="string">pwsh</span></span><br><span class="line"><span class="attr">        env:</span></span><br><span class="line"><span class="attr">          githubFullName:</span> <span class="string">$&#123;&#123;</span> <span class="string">github.event.repository.full_name</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">          upUrl:</span> <span class="string">$&#123;&#123;</span> <span class="string">steps.queryReleaseMacos.outputs.upload_url</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">          ref:</span> <span class="string">$&#123;&#123;</span> <span class="string">github.event.ref</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">        run:</span> <span class="string">|</span></span><br><span class="line"><span class="string">          # upUrl不为空，导出就完事</span></span><br><span class="line"><span class="string">          if ($&#123;env:upUrl&#125;.Length -gt 0) &#123;</span></span><br><span class="line"><span class="string">              $v=$&#123;env:upUrl&#125;</span></span><br><span class="line"><span class="string">              echo "::set-env name=uploadUrl::$v"</span></span><br><span class="line"><span class="string">              return</span></span><br><span class="line"><span class="string">          &#125; </span></span><br><span class="line"><span class="string">          [string]$tag = $&#123;env:ref&#125;.Substring($&#123;env:ref&#125;.LastIndexOf('/') + 1)</span></span><br><span class="line"><span class="string">          [string]$url = 'https://api.github.com/repos/' + $&#123;env:githubFullName&#125; + '/releases/tags/' + $&#123;tag&#125;</span></span><br><span class="line"><span class="string">          $response = Invoke-RestMethod -Uri $url -Method Get</span></span><br><span class="line"><span class="string">          [string]$latestUpUrl = $response.upload_url</span></span><br><span class="line"><span class="string">          Write-Host 'latestUpUrl:'$latestUpUrl</span></span><br><span class="line"><span class="string">          echo "::set-env name=uploadUrl::$latestUpUrl"</span></span><br><span class="line"><span class="string">          Write-Host 'env uploadUrl:'$&#123;env:uploadUrl&#125;</span></span><br><span class="line"><span class="string">      # tag 上传Release</span></span><br><span class="line"><span class="string"></span><span class="attr">      - name:</span> <span class="string">uploadRelease</span></span><br><span class="line"><span class="attr">        id:</span> <span class="string">uploadRelease</span></span><br><span class="line"><span class="attr">        if:</span> <span class="string">startsWith(github.event.ref,</span> <span class="string">'refs/tags/'</span><span class="string">)</span></span><br><span class="line"><span class="attr">        env:</span></span><br><span class="line"><span class="attr">          GITHUB_TOKEN:</span> <span class="string">$&#123;&#123;</span> <span class="string">secrets.GITHUB_TOKEN</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">        uses:</span> <span class="string">actions/upload-release-asset@v1.0.1</span></span><br><span class="line"><span class="attr">        with:</span></span><br><span class="line"><span class="attr">          upload_url:</span> <span class="string">$&#123;&#123;</span> <span class="string">env.uploadUrl</span> <span class="string">&#125;&#125;</span></span><br><span class="line"><span class="attr">          asset_path:</span> <span class="string">./bin/$&#123;&#123;</span> <span class="string">env.targetName</span> <span class="string">&#125;&#125;.dmg</span></span><br><span class="line"><span class="attr">          asset_name:</span> <span class="string">$&#123;&#123;</span> <span class="string">env.targetName</span> <span class="string">&#125;&#125;.dmg</span></span><br><span class="line"><span class="attr">          asset_content_type:</span> <span class="string">application/applefile</span></span><br></pre></td></tr></table></figure>

<h3 id="结果和代码"><a href="#结果和代码" class="headerlink" title="结果和代码"></a>结果和代码</h3><p><img src="/images/QtActions2/2.png" alt=""></p>
<p>代码在github <a href="https://github.com/jaredtao/HelloActions-Qt" target="_blank" rel="noopener">HelloActions-Qt</a></p>
<p>另外在涛哥的Qml控件库TaoQuick，也使用了这一套配置</p>
<p> <a href="https://github.com/jaredtao/TaoQuick" target="_blank" rel="noopener">TaoQuick</a></p>

    </div>
    
    <div class="reward" ontouchstart>
    <div class="reward-wrap">赏
        <div class="reward-box">
            
            <span class="reward-type">
                <img class="alipay" src="/img/zhifubao.jpg"><b>支付宝打赏</b>
            </span>
            
            
            <span class="reward-type">
                <img class="wechat" src="/img/weixin.jpg"><b>微信打赏</b>
            </span>
            
        </div>
    </div>
    <p class="reward-tip">
        为众人抱薪者,不可使其冻毙于霜雪
    </p>
</div>
    
    <div class="post-footer">
        <div>
            
            转载声明：
            文章采用<a href="http://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">知识共享署名-非商业性使用-相同方式共享 4.0 国际许可协议</a>进行许可, 转载请注明出处 © <a href="https://jaredtao.github.io" target="_blank">武威的涛哥</a>
            
            
        </div>
        <div>
            
        </div>
    </div>
</article>
<div class="article-nav prev-next-wrap clearfix">
    
    <a href="/2019/12/04/%E7%8E%A9%E8%BD%ACQt(12)-github-Actions%E7%BC%93%E5%AD%98%E4%BC%98%E5%8C%96/" class="pre-post btn btn-default" title='玩转Qt(12)-github-Actions缓存优化'>
        <i class="fa fa-angle-left fa-fw"></i><span class="hidden-lg">上一篇</span>
        <span class="hidden-xs">
            玩转Qt(12)-github-Actions缓存优化</span>
    </a>
    
    
    <a href="/2019/11/19/%E7%8E%A9%E8%BD%ACQt(10)-github-Actions%E8%87%AA%E5%8A%A8%E5%8C%96%E7%BC%96%E8%AF%91/" class="next-post btn btn-default" title='玩转Qt(10)-github-Actions自动化编译'>
        <span class="hidden-lg">下一篇</span>
        <span class="hidden-xs">
            玩转Qt(10)-github-Actions自动化编译</span><i class="fa fa-angle-right fa-fw"></i>
    </a>
    
</div>

<div id="comments">
    

<div id="vcomments" class="valine"></div>

<script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script>
<script src="/assets/valine.min.js"></script>

<script>
new Valine({
    av: AV,
    el: '#vcomments',
    appId: 'qegD4552u6FU9HoNDvRsonko-gzGzoHsz',
    appKey: 'eitB2FV5n2qyMHcDM7x6EQpt',
    placeholder: '说点什么吧',
    notify: false,
    verify: true,
    avatar: 'mm',
    meta: 'nick,mail'.split(','),
    pageSize: '10',
    path: window.location.pathname,
    lang: 'zh-CN'.toLowerCase()
})
</script>


</div>


                </main>
                
                    <aside id="article-toc" role="navigation" class="col-md-4">
    <div class="widget">
        <h3 class="title">
            文章目录
        </h3>
        
        <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#简介"><span class="toc-text">简介</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Qt项目的编译流程"><span class="toc-text">Qt项目的编译流程</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#Qt项目的发布流程"><span class="toc-text">Qt项目的发布流程</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#查找依赖"><span class="toc-text">查找依赖</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#制作包"><span class="toc-text">制作包</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#上传"><span class="toc-text">上传</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#定制发布流程"><span class="toc-text">定制发布流程</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#发布时机"><span class="toc-text">发布时机</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#打包步骤"><span class="toc-text">打包步骤</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#多平台发布"><span class="toc-text">多平台发布</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#最终配置"><span class="toc-text">最终配置</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#windows版的最终配置"><span class="toc-text">windows版的最终配置</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#MacOS最终配置"><span class="toc-text">MacOS最终配置</span></a></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#结果和代码"><span class="toc-text">结果和代码</span></a></li></ol></li></ol>
        
    </div>
</aside>
                
            </div>
        </div>
    </section>
    <footer class="main-footer">
    <div class="container">
        <div class="row">
        </div>
    </div>
</footer>
<a id="back-to-top" class="icon-btn hide">
    <i class="fa fa-chevron-up"></i>
</a>
    <div class="copyright">
    <div class="container">
        <div class="row">
            <div class="col-sm-12">
                <div class="busuanzi">
    
    访问量:
    <strong id="busuanzi_value_site_pv">
        <i class="fa fa-spinner fa-spin"></i>
    </strong>
    &nbsp; | &nbsp;
    访客数:
    <strong id="busuanzi_value_site_uv">
        <i class="fa fa-spinner fa-spin"></i>
    </strong>
    
</div>
            </div>
            <div class="col-sm-12">
                <span>Copyright &copy;
                    2019
                    
                </span> |
                <span>
                    Powered by <a href="//hexo.io" class="copyright-links" target="_blank" rel="nofollow">Hexo</a>
                </span> |
                <span>
                    Theme by <a href="//github.com/shenliyang/hexo-theme-snippet.git" class="copyright-links" target="_blank" rel="nofollow">Snippet</a>
                </span>
            </div>
        </div>
    </div>
</div>



<script src="/assets/tagcanvas.min.js?rev=2.9.js"></script>

<script>
var tagOption = {
    textColour: '#444', // 字体颜色
    outlineMethod: 'block', // 选中模式
    outlineColour: '#FFDAB9', // 选中模式的颜色
    interval: 30 || 30, // 动画帧之间的时间间隔，值越大，转动幅度越大
    textHeight: 13,
    outlineRadius: 3,
    freezeActive: true || '', // 选中的标签是否继续滚动
    frontSelect: true || '', // 不选标签云后部的标签
    initial: [0.1, -0.1],
    depth: 0.5,
    decel: 0.95,
    maxSpeed: 0.03,
    reverse: true || '', // 是否反向触发
    fadeIn: 500, // 进入动画时间
    wheelZoom: false || '' // 是否启用鼠标滚轮
}
TagCanvas.Start('tag-cloud-3d', '', tagOption);
</script>


<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>


<script src="/js/app.js?rev=@@hash.js"></script>

</body>
</html>